package com.ruoyi.compete.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.compete.domain.OtherTechInnCompete;
import com.ruoyi.compete.service.IOtherTechInnCompeteService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 其他科技创新竞赛Controller
 * 
 * @author ruoyi
 * @date 2024-11-13
 */
@RestController
@RequestMapping("/compete/compete")
public class OtherTechInnCompeteController extends BaseController
{
    @Autowired
    private IOtherTechInnCompeteService otherTechInnCompeteService;

    /**
     * 查询其他科技创新竞赛列表
     */
    @PreAuthorize("@ss.hasPermi('compete:compete:list')")
    @GetMapping("/list")
    public TableDataInfo list(OtherTechInnCompete otherTechInnCompete)
    {
        startPage();
        List<OtherTechInnCompete> list = otherTechInnCompeteService.selectOtherTechInnCompeteList(otherTechInnCompete);
        return getDataTable(list);
    }

    /**
     * 导出其他科技创新竞赛列表
     */
    @PreAuthorize("@ss.hasPermi('compete:compete:export')")
    @Log(title = "其他科技创新竞赛", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OtherTechInnCompete otherTechInnCompete)
    {
        List<OtherTechInnCompete> list = otherTechInnCompeteService.selectOtherTechInnCompeteList(otherTechInnCompete);
        ExcelUtil<OtherTechInnCompete> util = new ExcelUtil<OtherTechInnCompete>(OtherTechInnCompete.class);
        util.exportExcel(response, list, "其他科技创新竞赛数据");
    }

    /**
     * 获取其他科技创新竞赛详细信息
     */
    @PreAuthorize("@ss.hasPermi('compete:compete:query')")
    @GetMapping(value = "/{oticId}")
    public AjaxResult getInfo(@PathVariable("oticId") Long oticId)
    {
        return success(otherTechInnCompeteService.selectOtherTechInnCompeteByOticId(oticId));
    }

    /**
     * 新增其他科技创新竞赛
     */
    @PreAuthorize("@ss.hasPermi('compete:compete:add')")
    @Log(title = "其他科技创新竞赛", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OtherTechInnCompete otherTechInnCompete)
    {
        SysUser user= SecurityUtils.getLoginUser().getUser();
        otherTechInnCompete.setDeptId(105L);
        otherTechInnCompete.setUserId(user.getUserId());
        return toAjax(otherTechInnCompeteService.insertOtherTechInnCompete(otherTechInnCompete));
    }

    /**
     * 修改其他科技创新竞赛
     */
    @PreAuthorize("@ss.hasPermi('compete:compete:edit')")
    @Log(title = "其他科技创新竞赛", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OtherTechInnCompete otherTechInnCompete)
    {
        return toAjax(otherTechInnCompeteService.updateOtherTechInnCompete(otherTechInnCompete));
    }

    /**
     * 删除其他科技创新竞赛
     */
    @PreAuthorize("@ss.hasPermi('compete:compete:remove')")
    @Log(title = "其他科技创新竞赛", businessType = BusinessType.DELETE)
	@DeleteMapping("/{oticIds}")
    public AjaxResult remove(@PathVariable Long[] oticIds)
    {
        return toAjax(otherTechInnCompeteService.deleteOtherTechInnCompeteByOticIds(oticIds));
    }
}
